<template>
	<div class="gk-layout-container">
		<div class="gk-layout-header">
			<!--工具栏-->
			<s-query perms="core:coreTask"   @click="findPage" >
				<s-dict name="taskStatus" v-model="filters.status" />
				<el-form-item>
					<el-input v-model.trim="filters.boxCode" placeholder="请输入盘码"></el-input>
				</el-form-item>	 
					 
			</s-query>
		</div>
	
	
		

		<div class="gk-layout-main">
			<my-table :data="pageResult.content"  :loading="loading"  >
				<el-table-column :label="$t('action.desc')" width="50" fixed="left"  header-align="center" align="center">
				  <template slot-scope="scope">   {{scope.$index+1}}   </template>
				</el-table-column> 
				<column  prop="status" label="状态"     :formatter="selectionFormat" >  </column>
				<column   prop="boxCode" label="条码"   />  
				<column   prop="src" label="起始位置"   /> 
				<column   prop="des" label="目标位置"   />  

				<column  prop="createTime" label="创建时间"   :formatter= "dateFormat" />
				<column prop="finshTime" label="完成时间"     :formatter= "dateFormat" /> 
				
				<el-table-column  header-align="center"  align="center"    :label="$t('action.operation')" >
					<template slot-scope="scope">
						<kt-button icon="fa fa-edit"  :label="$t('action.showDetail')"  perms="core:coreTask:showDetail"    @click="handleShowDetail(scope.$index, scope.row)" />
					</template>
				</el-table-column>
			</my-table>
		</div>
		<!--分页栏-->
		<div class="toolbar gk-layout-footer"  style="padding:10px;">
		  
		  <el-pagination layout="total, prev, pager, next, jumper"  @current-change="findPage"
						 :current-page="filters.pageNum"
						 :page-size="filters.pageSize"
						 :total="pageResult.totalSize"
						 style="float:right;">
		  </el-pagination>
		</div>


		<!--新增编辑界面-->
		<el-dialog :title="'查看'" width="70%" :visible.sync="editDialogVisible" :close-on-click-modal="false">
			<el-form :model="dataForm" label-width="80px" ref="dataForm" :size="global.gSize" label-position="right">
				<el-row :gutter="20">

					<el-col :span="8">
						<s-dict-form name="taskStatus" v-model="dataForm.status" />
						 
					</el-col>
					<el-col :span="8">
						<el-form-item label="开始" prop="taskType">
							<el-input v-model="dataForm.src" style="width: 100%;" :disabled="false">
								
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="8">
						<el-form-item label="结束" prop="taskType">
							<el-input v-model="dataForm.des" style="width: 100%;" :disabled="false">
								
							</el-input>
						</el-form-item>
					</el-col>
				</el-row>
			
			</el-form>
			<div class="gk-layout-main" style="height:350px" >
				<my-table :data="pageResultDetail.content"   :loading="loading"  >
					<el-table-column :label="$t('action.desc')" width="50" fixed="left"  header-align="center" align="center">
					  <template slot-scope="scope">   {{scope.$index+1}}   </template>
					</el-table-column>
					<column    prop="taskNo" label="任务号"   >  </column>
					<el-table-column header-align="center"  align="center"   prop="src" label="起始位置"  key="pos"  >  </el-table-column>
					<el-table-column header-align="center"  align="center"  prop="des" label="目标位置"   key="des"   >  </el-table-column>
					
					<el-table-column header-align="center"  align="center"   prop="createTime" label="创建时间"  key="createTime"  :formatter= "dateFormat" >  </el-table-column>
					<el-table-column header-align="center"  align="center"   prop="type" label="类型"     key="type" :formatter= "selectionFormat" >  </el-table-column>
					<el-table-column header-align="center"  align="center"   prop="status" label="状态"     key="status" :formatter= "selectionFormat1" >  </el-table-column>
				</my-table>
			</div>
		</el-dialog>
	</div>
</template>

<script>
	import Column from "@/views/Core/Column"
	import KtButton from "@/views/Core/KtButton"
	import { format } from "@/utils/datetime"
	import MyTable from "@/views/Core/MyTable"
	import SDict from "@/components/Kj/SDict"
	import SDictForm from "@/components/Kj/SDictForm"
		import SQuery from "@/components/Kj/SQuery"
		   import {getItemName,dictsFormat} from "@/utils/myUtil"
	export default {
		components: {
		Column,
		KtButton,
		MyTable,
		SQuery,SDict,SDictForm

		},
		data() {
			return {
				size: 'small',
				filters: {
					pageNum: 1, 
					pageSize: this.global.pageSize,
					boxCode:""
				},
			 
				loading:false,
			 
				pageResult: {},
				pageResultDetail: {},
				operation: false, // true:新增, false:编辑
				editDialogVisible: false, // 新增编辑界面是否显示
				editLoading: false,
				dataFormRules: {
					label: [
						{ required: true, message: '请输入名称', trigger: 'blur' }
					]
				},
				// 新增编辑界面数据
				dataForm: {
					id: null,
					stockId: null,
					areaId: null,
					boxCode: null,
					status: null,
					taskType: null,
					createTime: null,
					finshTime: null,
					relyTaskId: null,
					maxStock: null,
					info: null,
					bussType: null,
					priority: null,
					src: null,
				}
			}
		},
		methods: {
			// 获取分页数据
			findPage: function (data) {
				if(data!=-1){
					data=data||1;
				
					this.filters.pageNum =data
					 
				}
				 
				this.$api.coreTask.findPage(this.filters).then((res) => {
					this.pageResult = res.data
				}) 
			},
			// 获取明细数据
			findDetailPage: function (data) { 
				this.$api.coreTask.GetListByTaskId(data).then((res) => {
					this.pageResultDetail = { content: res.data }
				}) 
			},
			// 显示详情界面
			handleShowDetail: function (index,row) {
				this.editDialogVisible = true
				this.dataForm = Object.assign({}, row)
				this.findDetailPage(row);
			},
			// 时间格式化
			dateFormat: function (row, column, cellValue, index) {
				return format(row[column.property])
			},
			selectionFormat: function (row, column, cellValue, index) {
				let key = ""
			
				let propt = column.property;
				if (propt == "taskType") {
					key = "taskType"
				} else if (propt == "status") {
					key = "taskStatus"
				} else if (propt == "type") {
					key = "paramType"
				}
				
				  return dictsFormat( key,cellValue);
			},
			selectionFormat1: function (row, column, cellValue, index) { 
				  return dictsFormat( "paramStatus",cellValue);
			}
		},
		mounted() {
			
			this.findPage(1)
		}
	}
</script>

<style scoped>

</style>